#include "TokenizedFile.h"
#include "util/StringUtil.h"
#include "exceptions.h"

TokenizedFile::TokenizedFile() {}

void TokenizedFile::open(std::string path) {
	file.open(path.c_str(), std::ios::in);
	if (!file.is_open()) {
		throw FileException("Could not open " + path);
	}
}

TokenLine TokenizedFile::getLine(const char delimiter) {
	std::getline(file, line);
	line = StringUtil::trim(line);
	TokenLine tokenLine(line, delimiter);
	return tokenLine;
}

bool TokenizedFile::hasLines() {
	return !file.eof();
}

TokenizedFile::~TokenizedFile() {
	if (file.is_open()) {
		file.close();
	}
}
